<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <link rel="icon" href="custom-path/favicon.ico" type="image/x-icon">
</head>
<body>
<input type="text" id="message">
<button id="send-button">发送</button>
<script>
    // 这里构造函数首字母要大写，是 WebSocket 而不是 websocket
    let websocket = new WebSocket("ws://127.0.0.1:8083/test");
    websocket.onopen = function () {
        console.log("连接成功");
    };
    // 注意这里是 onclose，你之前多写了一个 o，写成 oonclose 了
    websocket.onclose = function () {
        console.log("连接断开");
    };
    websocket.onerror = function () {
        console.log("连接异常");
    };
    websocket.onmessage = function (e) {
        console.log("收到消息" + e.data);
    };
    let messageInput = document.querySelector('#message');
    let sendButton = document.querySelector('#send-button');
    sendButton.onclick = function () {
        console.log("websocket发送消息：" + messageInput.value);
        websocket.send(messageInput.value);
    };
</script>
</body>
</html>